function thresholdAnalysisMain(inDir,filter,outDir)

densities=0.75:0.05:0.95;
nSurr=50;

files=dir(fullfile(inDir,filter));

nConds=length(files);
nDensities=length(densities);
 
fileName=files(1).name;
info=whos('-file',fullfile(inDir,fileName));
varName=info.name;
load(fullfile(inDir,fileName),varName);
nSubjs=size(eval(varName),1);%pliXSubjs nsubjs X ch X ch
nParam=7;
m=zeros(nConds,nDensities,nSubjs,nParam);

for cond=1:nConds
    fileName=files(cond).name;
    info=whos('-file',fullfile(inDir,fileName));
    varName=info.name;
    load(fullfile(inDir,fileName),varName);
    for d=1:nDensities
        
        for i=1:nSubjs  
            subj=squeeze(eval(strcat(varName,'(i,:,:)')));
            [m(cond,d,i,:)]=thresholdAnalysis(subj,densities(d),nSurr);
        end
    end
end
save(fullfile(outDir,'densityAnalysis.mat'),'m','densities','nSurr','files');